<template>
	<view>
		<view style="font-size: 1.2rem;font-weight: bold;text-align: center;width:100%;height:80upx;line-height:80upx;margin:40upx xuto">学校和餐厅选择</view>
		 <!-- <u-picker ref="uPicker" :show="rantCateDia" :columns="columns"  title="餐厅" @cancel="onClose1"  @confirm="confirm" @change="changeHandler"></u-picker> -->
		<u-collapse
		    @change="change"
		    @close="close"
		    @open="open"
			accordion
		  >
		    <u-collapse-item v-for="item in scolRentData"
		      :title="item.schoolName"
		      :name="item.schoolId"
		    >
		      <u-radio-group
		          v-model="deptName"
		          placement="column"
		          @change="groupChange"
		        >
		          <u-radio
		            :customStyle="{marginBottom: '8px'}"
		            v-for="(it, index) in item.rest"
					activeColor="#1E8550"
		            :key="index"
		            :label="it.deptName"
		            :name="it.deptName"
		            @change="radioChange(it.deptId)"
		          >
		          </u-radio>
		        </u-radio-group>
		    </u-collapse-item>
		  </u-collapse>
		  <view style="width:96%;position:fixed;bottom:20rpx;left:50%;right:50%; transform: translate(-50%, -50%);" @click="confirm">
		    <u-button  color="#1E8550" round size="large">确定</u-button>
		  </view>
	</view>
</template>

<script>
	import {
	 getTreeData
	} from '@/api/user'
	export default {
		data() {
			return {
				columns: [[],[]],
				columnData: [[]],
				scolArr:[[],[]],
				deptArr:[[]],
				scholOptData:[],
				scolRentData:[],
				schoolId:'',
				deptId:'',
				deptName:'',
				rantCateDia:false
			}
		},
		created(){
			this.initData()
		},
		methods: {
			onClose1(){
			    this.rantCateDia=false
			},
			change(val){
				console.log("vvaa",val)
			},
			close(){},
			open(val){
				this.schoolId = val
				let schools = this.scolRentData.filter(item=>{
					return item.schoolId == val
				})[0]
				this.deptName = schools.rest[0].deptName
				this.deptId = schools.rest[0].deptId
				console.log("deptName",this.deptName)
			},
			 groupChange(n) {
			    console.log('groupChange', n);
				this.deptName = n
		    },
		    radioChange(n) {
				this.deptId = n
		    },
			confirm() {
				if(this.deptId=="" || this.deptId == null){
					return uni.showToast({
					    title: "请先选择餐厅！",
						icon:'error'
					})
				}
				let deptDas = {
					scode:this.schoolId,
					rcode:this.deptId,
					dname:this.deptName
				}
				uni.setStorage({
					key: 'deptdas',
					data: JSON.stringify(deptDas),
					complete: function () {
						uni.switchTab({
							url: "../student/index"
						})	
					}
				});
			},
			initData(){
				let params = {pageNum:1,pageSize:50}
				getTreeData(params).catch(response=>{
					if(response.data){
						this.scolRentData = response.data.school
					}
				})
			}
		}
	}
</script>

<style>

</style>
